var util = require('../../utils/util.js')
var app = getApp()
Page({
  data: {
    userInfo: [],
    titleback : "https://liuyan.ijiechen.com/img/titleback.png",
    userback  : "https://liuyan.ijiechen.com/img/userback.png",
    pageback  : "https://liuyan.ijiechen.com/img/pageback.png",
    authorback: "https://liuyan.ijiechen.com/img/authorback2.png",
    dearimg   : "https://liuyan.ijiechen.com/img/dear222.png",
    fromimg   : "https://liuyan.ijiechen.com/img/from.png",
    liuyanban : "https://liuyan.ijiechen.com/img/liuyanban4.png",
    liuyan    : "https://liuyan.ijiechen.com/img/liuyan.png",
    liuyancontain: "暂无留言内容" ,
    defaultSize: 'default',
    primarySize: 'default',
    warnSize: 'default',
    disabled: false,
    plain: false,
    loading: false,

 
    imgUrls: [
        'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
        'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
        'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    indicatorDots: true,
   
    autoplay: false,
    interval: 5000,
    duration: 1000,
    circular: true 
   
  },
  onLoad: function (options) {
    var that = this
    var desk_code_fetch= 'nocode';
    console.log('global desk_code is')
    console.log(app.globalData.desk_code);
    var scene = decodeURIComponent(options.scene)
    console.log(scene);
    
    if (scene!=undefined){
      getApp().globalData.desk_code = scene;
    }
    else if (app.globalData.desk_code == ''){
      getApp().globalData.desk_code = desk_code_fetch;
    }
   
    console.log(app.globalData.desk_code);
    // app.getUserInfo(function (userInfo) {
    //   //更新数据
    //   // console.log(userInfo)
    //   that.setData({
    //     userInfo: userInfo
    //   })
    //   that.update()
    // }),
    wx.request({      
      url: 'https://liuyan.ijiechen.com/front/show-msg',
      data: {
        desk_code: app.globalData.desk_code,      
      },  
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {      
        if (res.data.slide!=undefined){
          var slide = res.data.slide
        }
        else{
          var slide = this.imgUrls
        }
        
        that.setData({
          liuyancontain: res.data.content,
          imgUrls:slide
        })
      }   
    })
  },
  //下拉刷新
  // onPullDownRefresh: function () {
  //   var that = this;
  //   that.onLoad(that.data.dgGlobal_options);
  //   setTimeout(() => {
  //     wx.stopPullDownRefresh();
  //   }, 1000);  
  // },
  onShareAppMessage: function () {
    var that = this;
    var shareTitle = '留言板';
    var shareDesc  = '留言板小程序';
    var sharePath  = 'pages/liuyan/liuyan';
    return {
      title: shareTitle,
      desc: shareDesc,
      imageUrl: '',
      path: sharePath
    }
  },
  getuserinfo:function(e){
      console.log(e)
      console.log(e.detail.errMsg)
      //存储为全局变量
      getApp().globalData.userInfo = e.detail.userInfo;
      console.log(app.globalData.userInfo)
      wx.navigateTo({
        url: '../setliuyan/setliuyan',
      })
    
  }
})
